#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int t, m, n, V, l;
int d[N], v0[N], a[N], p[N];
int num = 0;
struct biqujian {
    int l, r;
    bool operator< (const biqujian &t) const {
        if (t.l == l) {
            return r < t.r;
        } else {
            return l < t.l;
        }
    }
}cdt[N];
int vt(int u, int x) {
    return v0[u] * v0[u] + 2 * a[u] * x;
}
bool bin_search(int u) {
    // search p
    if (d[u] > p[m]) {
        
        return false;
    }
    int lp = lower_bound(p + 1, p + 1 + m, d[u]) - p;
    if (a[u] >= 0 && vt(u, p[lp] - d[u]) > V * V) {
        
        cdt[++num] = {lp, m};
        return true;
    }
    if (a[u] <= 0 && vt(u, p[m] - d[u]) > V * V) {
        
        
        cdt[++num] = {lp, m};
        return true;
    }
    if (a[u] <= 0 && vt(u, p[lp] - d[u]) <= V * V) {
        
        
        return false; 
    }
    if (a[u] >= 0 && vt(u, p[m] - d[u]) <= V * V) {
        
        return false; 
    }
    if (a[u] >= 0) {
        int l = lp, r = m;
        while (l + 1 < r) {
            int mid = (l + r) >> 1;
            if (vt(u, p[mid] - d[u]) > V * V) {
                r = mid;
            } else {
                l = mid;
            }
        }
        
        
        cdt[++num] = {r, m};
        return true;
        
    }
    else if (a[u] < 0) {
        int l = lp, r = m;
        while (l + 1 < r) {
            int mid = (l + r) >> 1;
            if (vt(u, p[mid] - d[u]) > V * V) {
                l = mid;
            } else {
                r = mid;
            }
        }
        
        
        
        cdt[++num] = {lp, l};
        return true;
    }
    
}
int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    scanf("%d", &t);
    while (t--) {
        num = 0;
        scanf("%d%d%d%d", &n, &m, &l, &V);
        for (int i = 1; i <= n; i++) {
            scanf("%d%d%d", &d[i], &v0[i], &a[i]);
        }
        for (int i = 1; i <= m; i++) {
            scanf("%d", &p[i]);
        }
        int cnt = 0, ans = 0;
        for (int i = 1; i <= n; i++) {
            if (bin_search(i)) {
                cnt++;
            }
        }
        sort(cdt + 1, cdt + 1 + num);
        int i = 1, j = 1, minr;
        while (i <= num) {
            minr = cdt[i].r;
            while (cdt[j].l <= minr && j <= num + 1) {
                minr = min(minr, cdt[j].r);
                j++;
            }
            ans++;
            i = j;
        }
        cout << cnt << ' ' << m - ans << endl;
    }
    return 0;
}